package com.ming_za.odupdaterserver.spring_modify;

import com.ming_za.odupdaterserver.core.config.ConfigManager;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TomcatConfig {

    private final ConfigManager configManager;

    public TomcatConfig(ConfigManager configManager) {
        this.configManager = configManager;
    }

    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> webServerFactoryCustomizer() {
        return factory -> {
            int port = configManager.getPort().getValue();
            factory.setPort(port);
        };
    }
}
